package com.ruoyi.finance.service.impl;

import com.ruoyi.finance.service.ICommissionDeliverySituationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.finance.domain.CommissionDeliverySituation;
import com.ruoyi.finance.mapper.CommissionDeliverySituationMapper;

import java.util.Date;
import java.util.List;

/**
 * 提成发货情况Service业务层处理
 *
 * @author admin
 * @date 2023-10-19
 */
@Service
public class CommissionDeliverySituationServiceImpl implements ICommissionDeliverySituationService {
    @Autowired
    private CommissionDeliverySituationMapper commissionDeliverySituationMapper;

    /**
     * 查询提成发货情况
     *
     * @param id 提成发货情况ID
     * @return 提成发货情况
     */
    @Override
    public CommissionDeliverySituation selectCommissionDeliverySituationById(Long id) {
        return commissionDeliverySituationMapper.selectCommissionDeliverySituationById(id);
    }

    /**
     * 查询提成发货情况列表
     *
     * @param commissionDeliverySituation 提成发货情况
     * @return 提成发货情况
     */
    @Override
    public List<CommissionDeliverySituation> selectCommissionDeliverySituationList(CommissionDeliverySituation commissionDeliverySituation) {
        return commissionDeliverySituationMapper.selectCommissionDeliverySituationList(commissionDeliverySituation);
    }

    /**
     * 查询提成发货情况列表
     *
     * @param commissionDeliverySituation 提成发货情况
     * @return 提成发货情况
     */
    @Override
    public List<CommissionDeliverySituation> selectSituationListForSync(CommissionDeliverySituation commissionDeliverySituation) {
        return commissionDeliverySituationMapper.selectSituationListForSync(commissionDeliverySituation);
    }

    /**
     * 查询提成发货情况列表
     *
     * @return 提成发货情况
     */
    @Override
    public List<CommissionDeliverySituation> selectCommissionSituation(Date commissionDate, Integer searchType) {
        CommissionDeliverySituation commissionDeliverySituation = new CommissionDeliverySituation();
        commissionDeliverySituation.setCommissionDate(commissionDate);
        commissionDeliverySituation.setSearchType(searchType);
        if (searchType == 1 || searchType == 2) {
            return commissionDeliverySituationMapper.searchDeliverySituationList(commissionDeliverySituation);
        } else if (searchType == 3) {
            return commissionDeliverySituationMapper.searchCheckSituationList(commissionDeliverySituation);
        } else if (searchType == 4) {
            return commissionDeliverySituationMapper.searchCheckSituationList1(commissionDeliverySituation);
        } else {
            return null;
        }
    }

    /**
     * 新增提成发货情况
     *
     * @param commissionDeliverySituation 提成发货情况
     * @return 结果
     */
    @Override
    public int insertCommissionDeliverySituation(CommissionDeliverySituation commissionDeliverySituation) {
        return commissionDeliverySituationMapper.insertCommissionDeliverySituation(commissionDeliverySituation);
    }

    /**
     * 修改提成发货情况
     *
     * @param commissionDeliverySituation 提成发货情况
     * @return 结果
     */
    @Override
    public int updateCommissionDeliverySituation(CommissionDeliverySituation commissionDeliverySituation) {
        if (commissionDeliverySituation.getDeliveryStatus() == 1) {
            if (commissionDeliverySituation.getCheckStatus() < 2) {
                commissionDeliverySituation.setCheckStatus(1);
            }
        } else {
            if (commissionDeliverySituation.getCheckStatus() < 2) {
                commissionDeliverySituation.setCheckStatus(0);
            }
            commissionDeliverySituation.setCommissionDate(null);
        }
        commissionDeliverySituation.setUpdateTime(DateUtils.getNowDate());
        return commissionDeliverySituationMapper.updateCommissionDeliverySituationStatus(commissionDeliverySituation);
    }

    /**
     * 修改提成发货情况
     *
     * @param list 提成发货情况
     * @return 结果
     */
    @Override
    public int batchUpdateCommissionDeliverySituation(List<CommissionDeliverySituation> list) {
        return commissionDeliverySituationMapper.batchUpdateCommissionDeliverySituation(list);
    }

    /**
     * 批量删除提成发货情况
     *
     * @param ids 需要删除的提成发货情况ID
     * @return 结果
     */
    @Override
    public int deleteCommissionDeliverySituationByIds(Long[] ids) {
        return commissionDeliverySituationMapper.deleteCommissionDeliverySituationByIds(ids);
    }

    /**
     * 删除提成发货情况信息
     *
     * @param id 提成发货情况ID
     * @return 结果
     */
    @Override
    public int deleteCommissionDeliverySituationById(Long id) {
        return commissionDeliverySituationMapper.deleteCommissionDeliverySituationById(id);
    }
}
